package homework;

import java.io.*;

public class Test07 {
    public static void main(String[] args) throws IOException {
        File dir = new File(".");
        File[] subs = dir.listFiles(f -> f.getName().endsWith(".txt"));
        for (File sub : subs) {
            String filename = sub.getName();
            String name = filename.substring(0, filename.lastIndexOf("."));
            name = name + "_cp";
            name = name + filename.substring(filename.lastIndexOf("."));
            FileInputStream fis = new FileInputStream(sub);
            FileOutputStream fos = new FileOutputStream(name);
            int len;
            byte[] data = new byte[1024 * 10];
            while ((len = fis.read(data)) != -1) {
                fos.write(data, 0, len);
            }
            fis.close();
            fos.close();
        }
        System.out.println("复制完毕");
    }
}
